
version 14
clear

cd "C:\A_Working_Directory\NSF_HSD\Experiments\kamchatka_sanctions\data_sanctions"
use sanctions_data_kamchatka_clean.dta, replace

				 
*******************************     
** TABLE 1: Effect of punishment and rewards on cooperation (Y==Investment) 
*******************************     
		estimates clear
	   gl tests "test1 test2 test3 test4 test5 test6" 

	   eststo R1: xtreg invest i.treatment round, robust
	test _b[0.treatment] = _b[1.treatment]
	estadd scalar test1=r(p): R1
	test _b[0.treatment] = _b[2.treatment]
	estadd scalar test2=r(p): R1
	test _b[0.treatment] = _b[3.treatment]
	estadd scalar test3=r(p): R1
	test _b[1.treatment] = _b[2.treatment]
	estadd scalar test4=r(p): R1
	test _b[1.treatment] = _b[3.treatment]
	estadd scalar test5=r(p): R1
	test _b[2.treatment] = _b[3.treatment]
	estadd scalar test6=r(p): R1

	   
	   eststo R2: xtreg invest i.treatment male age educ_yrs spend_time_group_avg round, robust
	test _b[0.treatment] = _b[1.treatment]
	estadd scalar test1=r(p): R2
	test _b[0.treatment] = _b[2.treatment]
	estadd scalar test2=r(p): R2
	test _b[0.treatment] = _b[3.treatment]
	estadd scalar test3=r(p): R2
	test _b[1.treatment] = _b[2.treatment]
	estadd scalar test4=r(p): R2
	test _b[1.treatment] = _b[3.treatment]
	estadd scalar test5=r(p): R2
	test _b[2.treatment] = _b[3.treatment]
	estadd scalar test6=r(p): R2

	
	esttab R1 R2 using "Table1-rev.rtf" , label cells(b(star fmt(%9.2f)) se(par fmt(%9.2f))) starlevels(* .10 ** .05 *** .01) ///
	stats(N $tests, fmt(0 3) ///
	labels("N" "TO=T1" "TO=T2" "TO=T3"   ///
	           "T1=T2" "T1=T3"  ///
	           "T2=T3" ///
						  ) )  ///	
	mlabels("Baseline (all)" "T1 (all)" "T2 (no outliers)" "T3(all)" ) collabels(none) ///
	addnotes("Robust standard errors are clustered at the group-level.") ///
	title("Table 1. Effect of punishment and rewards on cooperation (Y=Investment) ") replace	
	

	   				esttab using "Table1.rtf" , label cells(b(star fmt(%9.2f)) se(par fmt(%9.2f))) starlevels(* .10 ** .05 *** .01) ///
						stats(N chi2, fmt(%9.000f) labels("N" "Wald Chi2"))  ///
						mlabels("Equation (1)" "Equation (2)" "Equation (3)" "Equation (4)" ) collabels(none) ///
						addnotes("Robust standard errors in parentheses are clustered at the individual-level .") ///
						title("Table 1. Effect of punishment and rewards on cooperation (Y==Investment) ") replace	

			
*******************************     
** EER - TABLE 3. Punishment received relative to investment
*******************************

		gen treat1 = 0
		replace treat1 = 1 if treatment == 1
		gen invest_treat1 = invest*treat1
	
	** recall punishment received is equal to 3 x amount invested in punishment
	
		estimates clear	
		eststo: xtreg punishreceived invest round if (treatment == 1), r
		eststo: xtreg punishreceived invest round if (treatment == 3), r
    eststo: xtreg punishreceived invest treat1 invest_treat1 spend_time_group_avg round if (treatment == 3 | treatment == 1), r
    eststo: xtreg punishreceived invest treat1 invest_treat1 male age educ_yrs spend_time_group_avg round if (treatment == 3 | treatment == 1), r
		esttab using "table3_punishrec.rtf" , label cells(b(star fmt(%9.3f)) se(par fmt(%9.2f))) starlevels(* .10 ** .05 *** .01) stats(N, fmt(%9.0f) labels("N"))  mlabels("Model 1" "Model 2" "Model 3" "Model 4") collabels(none) addnotes("Robust standard errors are clustered at the individual level.") title("Punishment received relative to investment") replace

		
*******************************
**** EER - TABLE 4. amount received in sharing ***
*******************************
gen shocked_invest = shocked * invest 

		estimates clear
		eststo: xtreg amtreceived invest   round if treatment==1, r
		eststo: xtreg amtreceived shocked invest shocked_invest  round if treatment==2, r
		eststo: xtreg amtreceived shocked invest shocked_invest  round if treatment==3, r
		esttab using "table4_sharingrec1.rtf" , label cells(b(star fmt(%9.3f)) se(par fmt(%9.2f))) starlevels(* .10 ** .05 *** .01) stats(N, fmt(%9.0f) labels("N"))  mlabels("Treatment 1" "Treatment 2" "Treatment 3") collabels(none) addnotes("Robust standard errors are clustered at the individual level.") title("Amount received in sharing") replace

		estimates clear
		eststo: xtreg amtreceived invest   round if treatment==1, r
		eststo: xtreg amtreceived shocked invest shocked_invest  round if treatment==2, r
		eststo: xtreg amtreceived shocked invest shocked_invest male age educ_yrs spend_time_group_avg round if treatment==2, r
		eststo: xtreg amtreceived shocked invest shocked_invest  round if treatment==3, r
		eststo: xtreg amtreceived shocked invest shocked_invest male age educ_yrs spend_time_group_avg round if treatment==3, r
		esttab using "table4_sharingrec2.rtf" , label cells(b(star fmt(%9.3f)) se(par fmt(%9.2f))) starlevels(* .10 ** .05 *** .01) stats(N, fmt(%9.0f) labels("N"))  mlabels("Treatment 1" "Treatment 2" "Treatment 2" "Treatment 3" "Treatment 3") collabels(none) addnotes("Robust standard errors are clustered at the individual level.") title("Amount received in sharing") replace


**************************************************************
**** EER - TABLE 6. Below after reshape command ***
**************************************************************

**************************************************************
**** EER - TABLE 7. Below after reshape command ***
**************************************************************

	
**********************************************************************
*** EER - FIGURE 1 MAIN
**********************************************************************
	twoway (connected mean_iT1_stg2 round if stage1, sort mcolor(blue) lcolor(blue)) (connected mean_iT1_stg2 round if stage2, sort mcolor(blue) lcolor(blue)) (connected mean_iT2_stg2 round if stage1, sort mcolor(green) lcolor(green)) (connected mean_iT2_stg2 round if stage2, sort mcolor(green) lcolor(green)) (connected mean_iT3_stg2 round if stage1, sort mcolor(red) lcolor(red)) (connected mean_iT3_stg2 round if stage2, sort mcolor(red) lcolor(red))    , ytitle(Mean Group Activity) xtitle(Round) ylabel(0(10)50) xlabel(1(1)13) legend(order(1 "T1. no shock: punish+share " 3 "T2. shock: share only" 5 "T3. shock: punish+share" )) name(figure2b, replace)  plotregion(fcolor(white) lcolor(black) lwidth(vthin) ifcolor(white) ilcolor(black) ilwidth(vthin) ) scheme(s1mono)

	graph export fig1.png,  width(7480) replace

	
**********************************************************************
*** EER - FIGURE 2. MAIN PUNISHMENT BY ROUNDS***
**********************************************************************
	
			xtreg punish round if treatment == 1, r
			predict punish_rnd_t1
		
			xtreg punish round if treatment == 3, r
			predict punish_rnd_t3
	
			by round punish, sort: egen int count_punish1 = count(one) if treatment == 1
			by round punish, sort: egen int count_punish3 = count(one) if treatment == 3

		
			scatter punish round if round >=6 & treatment == 1 [w=count_punish1] , msymbol(circle_hollow)|| line punish_rnd_t1 round if round >=6 & treatment == 1, ytitle(Rubles spent punishing) ylabel(0(50)250) xtitle(Round) xlabel(6(1)13) title(Treatment 1-no risk)  name(punish_T1, replace) plotregion(fcolor(white) lcolor(black) lwidth(vthin) ifcolor(white) ilcolor(black) ilwidth(vthin) ) scheme(s1mono)

			scatter punish round if round >=6 & treatment == 3 [w=count_punish3] , msymbol(circle_hollow)|| line punish_rnd_t3 round if round >=6 & treatment == 3, ytitle(Rubles spent punishing) ylabel(0(50)250) xtitle(Round) xlabel(6(1)13) title(Treatment 3-risk) name(punish_T2, replace) plotregion(fcolor(white) lcolor(black) lwidth(vthin) ifcolor(white) ilcolor(black) ilwidth(vthin) ) scheme(s1mono)

		
		graph combine punish_T1 punish_T2, rows(1) ycommon xcommon   name(figure1, replace) saving(figure2.pdf, replace) scheme(sj) 

graph export fig2.png,  width(7480) replace


**********************************************************************
*** FIGURE #3 BELOW AFTER RESHAPE COMMAND ***
**********************************************************************

			
**********************************************************************
*** EER - FIGURE 4 MAIN - SHARING BY ROUND in treatments T1 and T3.***
**********************************************************************

***********************
** sharing over time **
***********************
			xtreg sharing round if treatment == 1, r
			predict share_rnd_t1
			
			xtreg sharing round if treatment == 2, r
			predict share_rnd_t2
			
			xtreg sharing round if treatment == 3, r
			predict share_rnd_t3

			
			by round sharing, sort: egen int count_sharing1 = count(one) if treatment == 1
			by round sharing, sort: egen int count_sharing2 = count(one) if treatment == 2
			by round sharing, sort: egen int count_sharing3 = count(one) if treatment == 3

	
			scatter sharing round if round >=6 & treatment == 1 [w=count_sharing1] , msymbol(circle_hollow)|| line share_rnd_t1 round if round >=6 & treatment == 1, ytitle(Rubles Shared) xtitle(Round) xlabel(6(1)13) title(Treatment 1) name(share_t1, replace) plotregion(fcolor(white) lcolor(black) lwidth(vthin) ifcolor(white) ilcolor(black) ilwidth(vthin) ) scheme(s1mono)
			scatter sharing round if round >=6 & treatment == 2 [w=count_sharing2] , msymbol(circle_hollow)|| line share_rnd_t2 round if round >=6 & treatment == 2, ytitle(Rubles Shared) xtitle(Round) xlabel(6(1)13) title(Treatment 2) name(share_t2, replace) plotregion(fcolor(white) lcolor(black) lwidth(vthin) ifcolor(white) ilcolor(black) ilwidth(vthin) ) scheme(s1mono)
			scatter sharing round if round >=6 & treatment == 3 [w=count_sharing3] , msymbol(circle_hollow)|| line share_rnd_t3 round if round >=6 & treatment == 3, ytitle(Rubles Shared) xtitle(Round) xlabel(6(1)13) title(Treatment 3) name(share_t3, replace) plotregion(fcolor(white) lcolor(black) lwidth(vthin) ifcolor(white) ilcolor(black) ilwidth(vthin) ) scheme(s1mono)

			
*graph combine share_t1 share_t2 share_t3, rows(1) ycommon xcommon  name(fig4share, replace) saving(fig4share.pdf, replace) scheme(sj) 
graph combine share_t1 share_t3, rows(1) ycommon xcommon  name(fig4share, replace) saving(fig4share.pdf, replace) scheme(sj) 

graph export fig4.png,  width(7480) replace


******************************************************************************************************************


******************************************
*** RESHAPE DATA ***
******************************************

do C:\A_Working_Directory\NSF_HSD\Experiments\kamchatka_sanctions\syntax_files\sanctions-kamchatka-reshape.do

		replace punish_others = . if investment_gap ==.
			* this sets punish_others = . for all of the player decisions ... i don't think this is necessary ...

** individual identifiers **

		gen prosocial_punish = 0
		replace prosocial_punish = 1 if punish_others>0 & punish_others~=.  & investment_gap>0
		
		gen antisocial_punish = 0
		replace antisocial_punish = 1 if punish_others>0 & punish_others~=.  & investment_gap<0
		
		gen zerosocial_punish = 0
		replace zerosocial_punish = 1 if punish_others>0 & punish_others~=.  & investment_gap==0

******************************************
** EER - FIGURE 3 - Antisocial and Prosocial Punishment **
******************************************

scatter punish_others investment_gap  if punish_others>0 & punish_others~=. & treatment ==1, ytitle(Punishment Given in Rubles) ylabel(0(50)250) xtitle(My Investment Less Other's Investment) title(Treatment 1-no risk) name(fig3_dict1, replace) plotregion(fcolor(white) lcolor(black) lwidth(vthin) ifcolor(white) ilcolor(black) ilwidth(vthin) ) scheme(s1mono)

scatter punish_others investment_gap  if punish_others>0 & punish_others~=. & treatment ==3, ytitle(Punishment Given in Rubles) ylabel(0(50)250) xtitle(My Investment Less Other's Investment) title(Treatment 3-risk) name(fig3_dict2, replace) plotregion(fcolor(white) lcolor(black) lwidth(vthin) ifcolor(white) ilcolor(black) ilwidth(vthin) ) scheme(s1mono)

		
		graph combine fig3_dict1 fig3_dict2, rows(1) ycommon xcommon   name(figure3, replace) saving(figure3.pdf, replace) scheme(sj) 

graph export fig3.png,  width(7480) replace


**************************************
**** MISC ***

xtset sub_id
gen invest_oth_shock = invest_others * shock_stack
table sub_id player_letter if roundcounts==1, statistic(total dictatorgiveto) 

table treatment_cont treatment  if roundcounts==1 & dictatorgiveto>0, statistic(mean dictatorgiveto finalearnings) statistic(n dictatorgiveto finalearnings) 

table treatment_cont treatment if roundcounts==1 & dictatorgiveto>0, statistic(mean dictatorgiveto finalearnings) statistic(sd dictatorgiveto finalearnings) 
table treatment_cont treatment if roundcounts==1 & dictatorgiveto>0, statistic(n dictatorgiveto finalearnings) 

table treatment_cont treatment if roundcounts==1 & dictatorgiveto==0, statistic(n dictatorgiveto finalearnings) 

******************************************
** TABLE 6. DICTATOR GIVING **
******************************************

estimates clear
		eststo: tobit dictatorgiveto invest_others  if roundcounts== 1 , vce(robust) ll(0)
		eststo: tobit dictatorgiveto invest_others shock_stack invest_oth_shock if roundcounts== 1 & treatment>=2, vce(robust)  ll(0)
		
		
		
		eststo: xttobit dictatorgiveto invest_others  if roundcounts== 1 ,  ll(0)
		eststo: xttobit dictatorgiveto invest_others shock_stack invest_oth_shock if roundcounts== 1 & treatment>=2,  ll(0) 

		*** Baseline round selected - original treatment
		eststo: tobit dictatorgiveto invest_others ib1.treatment_cont if roundcounts== 1 & treatment==0, vce(robust) ll(0)

		*** Treatments 2 or 3 selected relative
		eststo: tobit dictatorgiveto invest_others shock invest_oth_shock if roundcounts== 1 & treatment>=2, vce(robust)  ll(0)

			
		esttab using "table6_dictgive.rtf" , label cells(b(star fmt(%9.3f)) se(par fmt(%9.2f))) starlevels(* .10 ** .05 *** .01) stats(N, fmt(%9.0f) labels("N"))  mlabels("All Treatments, Tobit" "Treatment 2-3, Tobit" "All Treatments, fe" "Treatment 2-3, fe" ) collabels(none) addnotes("Robust standard errors are clustered at the individual level.") title("Dictator giving") replace

**************************************************************
**** EER - TABLE 7. Effect of previous punishment on current investment ***
**************************************************************
			 	gen pos_gap_dum = 0
				replace pos_gap_dum = 1 if investment_gap>=0
				table treatment pos_gap_dum if punish_adj>0, statistic(mean punish_adj) statistic(n punish_adj)
				** sig difference
				regress punish_adj pos_gap_dum if treatment == 1 & punish_adj>0, r
				
				** generate dummy for received anti-social punishment test if investment is less than those who didn't receive anti-social punishment
				
				
				gen anti_tag = .
				replace anti_tag = 0 if (treatment == 1 | treatment == 3)
				replace anti_tag = 1 if investment_gap<=0 & punish_adj >0 & anti_tag~=.
				replace anti_tag = . if punish_adj ==.
				replace anti_tag = . if investment_gap ==.
				
				table sub_id anti_tag if punish_adj>0 & treatment == 1 & punish_adj~=., statistic(mean punish_adj) statistic(n punish_adj) 
				
				** note that there is doublecounting for the session with a 4 person group sub_id 61-65
				
				** dropping all other players 
				
					drop if four_person == 1

					by sub_id round, sort: egen anti_tag_round = max(anti_tag)
					
					keep if invest_others == .
				
					xtset sub_id round
					
					gen anti_lagpunish = l.punishreceived * anti_tag_round
	
	
					xtset sub_id round
									
					
					xttobit punishgiven l.punishreceived anti_tag_round anti_lagpunish if treatment == 1  ,  ll(0)			
					
					** investment unaffected by punishment
					estimates clear	
					eststo: xtreg myinvest l.punishreceived round if (treatment == 1 | treatment == 3) & round>=5  , r
					eststo: xtreg myinvest l.punishreceived l.myinvest round if (treatment == 1 | treatment == 3) & round>=5  , r
					esttab using "table7_punishinvest-rev.rtf" , label cells(b(star fmt(%9.3f)) se(par fmt(%9.2f))) starlevels(* .10 ** .05 *** .01) stats(N, fmt(%9.0f) labels("N"))  mlabels("Model 1" "Model 2") collabels(none) addnotes("Robust standard errors are clustered at the individual level.") title("Effect of previous punishment on current investment") replace
					
			

		
			
			